#pragma once

#include "AsyncLibDef.h"

namespace AsyncLib
{

class CThreadpoolWait
{
public:
	CThreadpoolWait();
	~CThreadpoolWait();

	void Init();
	void Stop();
	void Exit();
	void AddTask(HANDLE hHandle, UINT nMilliseconds, std::function<void(DWORD)>&& fnCallback);

private:
	void OnCallback(PTP_WAIT pTpWait, DWORD dwResult);
	PTP_WAIT GetTpWait();
	void ReleaseTpWait(PTP_WAIT pTpWait);

	PTP_WAIT   m_pTpCaches[4];
	std::mutex m_mutex;
	std::unordered_map<PTP_WAIT, std::function<void(DWORD)>> m_mapTasks;
};

} // namespace AsyncLib
